package leetCode;

public class longestPalindrome {
    public static void main(String[] args) {
//        String s = "abcde";
//        String news = s.substring(0,3);
//        System.out.println(news);
        String s= longestPalindrome("babad");
        System.out.println(s);
        char c = 'a';
    }
    public static String longestPalindrome(String s) {
        int maxLen = 0;
        int begin = 0;
        if(s.length() == 1 || s.length() == 0) return s;

        for(int i = 0;i<s.length()-1;i++){
            for(int j = i+1;j<s.length();j++){
                if(isPalindrome(i,j,s) && j-i+1 >maxLen){
                    maxLen = j-i+1;
                    begin = i;
                }
            }
        }
        String s1 = s.substring(begin,begin+maxLen);
        return s1;
    }
    public static boolean isPalindrome(int left,int right,String s){
        while(left<=right){
            if(s.charAt(left) != s.charAt(right)){
                return false;
            }
            left++;
            right--;
        }
        return true;
    }
}
